<%--
  Created by IntelliJ IDEA.
  User: 华为
  Date: 2025/3/14
  Time: 15:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.23/dist/css/layui.css" rel="stylesheet">
</head>
<body>
<form class="layui-form layui-row layui-col-space16">
    <div class="layui-form-item">
        <label class="layui-form-label">
            状态
        </label>
        <div class="layui-input-block">
            <select name="state"  id="state" lay-filter="status">
                <option value="">请选择</option>
                <option value="0">待诊</option>
                <option value="1">已诊</option>
                <option value="2">退号</option>
            </select>
        </div>
        <input type="text" name="count" id="count">
    </div>

    <div class="layui-btn-container layui-col-xs12">
        <button class="layui-btn" lay-submit lay-filter="demo-table-search">Search</button>
        <button type="reset" class="layui-btn layui-btn-primary">Clear</button>
    </div>
</form>
<table class="layui-hide" id="ID-table-demo-search"></table>
<script type="text/html" id="demo-toolbar-setRowChecked">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">新增</button>
    </div>
</script>
<script type="text/html" id="toolDemo">
    <div class="layui-clear-space">
        {{#  if(${user.userGrade}==1){ }}
        <a class="layui-btn layui-btn-xs" lay-event="into">接诊</a>
        <a class="layui-btn layui-btn-xs" lay-event="out">退号</a>
        {{#  } }}

    </div>
</script>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="//unpkg.com/layui@2.9.23/dist/layui.js"></script>
<script src="/static/js/jquery-1.8.3.js"></script>
<script>
    layui.use(function(){
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        // 创建表格实例
        table.render({
            elem: '#ID-table-demo-search',
            url: '/registration/getList', // 此处为静态模拟数据，实际使用时需换成真实接口
            cols: [[
                {type: 'radio', title: '😊', fixed: true}, // 单选框
                {field:'imgUrl', title: '头像', width:80, sort: true, fixed: true,templet:function (obj) {
                        return '<img src=" '+ obj.imgUrl+'"/>'
                    }},
                {field:'registrationId', title: '挂号id', width:80, sort: true, fixed: true},
                {field:'registrationType', title: '就诊类型 0-初诊1-复诊', width:80,templet:function (obj) {
                        if(obj.registrationType==0){
                            return "初诊"
                        }else{
                            return "复诊"
                        }
                    }},
                {field:'sexId', title: '性别', width:80, sort: true,templet:function (obj) {
                        if(obj.sexId==0){
                            return "女"
                        }else if(obj.sexId==1){
                            return "男"
                        }else{
                            return "保密"
                        }
                    }},
                {field:'patientName', title: '患者姓名', width:80},
                {field:'phoneNumber', title: '手机号码',width: 80},
                {field:'birthDate', title: '出生日期', sort: true, width:80},
                {field:'idCard', title: '身份证号', sort: true, width:80},
                {field:'age', title: '年龄', sort: true, width:80},
                {field:'departmentName', title: '科室', sort: true, width:80},
                {field:'userName', title: '医生', sort: true, width:80},
                {field:'state', title: '挂号状态 0-待诊1-已诊2-退号', sort: true, width:80,templet:function (obj) {
                        if(obj.state==0){
                            return "待诊"
                        }else if(obj.state==1){
                            return "已诊"
                        }else if(obj.state==2){
                            return "退号"
                        }
                    }},
                {field:'remark', title: '退号原因', sort: true, width:80},
                {fixed: 'right', title:'操作', width: 134, minWidth: 125, templet: '#toolDemo'}
            ]],
            page: true,
            height: 310,
            toolbar: '#demo-toolbar-setRowChecked',
            request: {
                pageName: 'pageNum', // 页码的参数名称，默认：page
                limitName: 'pageSize' // 每页数据条数的参数名，默认：limit
            },
            parseData: function(res){ // res 即为原始返回的数据
                let state = $("#state").val();
                if(state!=''){
                    $("#count").val(res.data.total)
                }

                return {
                    "code": 0, // 解析接口状态
                    "msg": res.message, // 解析提示文本
                    "count": res.data.total, // 解析数据长度
                    "data": res.data.list // 解析数据列表
                };
            },
        });
        // 头工具栏事件
        table.on('toolbar(ID-table-demo-search)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            switch(obj.event){
                case 'getCheckData':
                    // var data = checkStatus.data;  // 获取选中行数据
                    // layer.alert(JSON.stringify(data));  // 显示 - 仅用于演示
                    // break;
                    location.href="/registration/toAdd"
            };
        });
        // 触发单元格工具事件
        table.on('tool(ID-table-demo-search)', function(obj){ // 双击 toolDouble
            var data = obj.data; // 获得当前行数据
            // console.log(obj)
            if(obj.event === 'into'){
                $.ajax({
                    url:"/visit/updAdd" ,
                    type: "post",
                    data: JSON.stringify(data),
                    contentType: "application/json",
                    dataType: "json",
                    success(res) {
                        if(res.code==200){
                            layer.alert(res.msg)
                            location.reload()
                        }
                    },
                    error() {

                    }
                })

            }else if(obj.event==="out"){
                location.href="/visit/toSet?registrationId="+data.registrationId;
            }
        });
        // 日期
        laydate.render({
            elem: '.demo-table-search-date'
        });
        // 搜索提交
        form.on('submit(demo-table-search)', function(data){
            var field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('ID-table-demo-search', {
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            layer.msg('搜索成功');
            return false; // 阻止默认 form 跳转
        });
    });
</script>

</body>
</html>
